import QtQuick
import QtQuick.Controls
import Tool 1.0
Item {

    property bool isLogined
    property string tabbarname :"用户界面"

    Component{
        id:userLogin
        Rectangle{

            Column{
                anchors.fill: parent
                spacing:8
                Row{
                    width: parent.width
                    height: parent.height/4-5
                    Text{
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: Text.AlignHCenter
                        width: parent.width/6
                        height: parent.height
                        font.pixelSize: 15
                        text:"账号："
                    }
                    TextField{
                        color:color_MaterialBlue
                        id:textFieldAcc
                        placeholderText: "账号"
                        height: parent.height
                        width: parent.width/6*5-10
                    }
                }

                Row{
                    width: parent.width
                    height: parent.height/4-5
                    Text{
                        verticalAlignment: Text.AlignVCenter
                        horizontalAlignment: Text.AlignHCenter
                        width: parent.width/6
                        height: parent.height
                        font.pixelSize: 15
                        text:"密码："
                    }

                    TextField{
                        color:color_MaterialBlue
                        // Material.accent: Material.Blue
                        id:textFieldPsw
                        placeholderText: "密码"
                        height: parent.height
                        width: parent.width/6*5-10
                    }
                }
                Rectangle{
                    width: parent.width
                    height: parent.height/5-5
                    // color:"red"
                    Row{
                        anchors.left: parent.left
                        anchors.margins: 10
                        height: parent.height
                        width: 200
                        spacing:10
                        CheckBox{
                            // Material.accent: Material.Blue
                            // color:color_MaterialBlue
                            // font.
                            // Material.color: Material.Blue
                            // anchors.left: parent.left
                            // font.
                            // contentItem: Text{
                            //     anchors.right: parent.right
                            //     text:"保存账号到本地"
                            //     color:color_MaterialBlue
                            // }
                            id:checkboxIsToSaveToLocation
                            height: parent.height
                            width: 20
                            anchors.margins: 10
                            // text:"保存账号到本地"
                            // icon.color: color_MaterialBlue

                        }
                        Text{
                            anchors.verticalCenter: parent.verticalCenter
                            color: color_MaterialBlue
                            font.bold: true
                            text:"保存账号到本地"
                            verticalAlignment: Text.AlignVCenter
                            horizontalAlignment: Text.AlignHCenter

                        }

                    }
                }


                Button{
                    width: parent.width
                    height: parent.height/4-5
                    Material.accent: Material.Blue
                    highlighted: true
                    Material.roundedScale: Material.SmallScale
                    text:"确定"
                    onClicked: {
                        Tool.toolWriteToLogin(textFieldAcc.text,textFieldPsw.text,checkboxIsToSaveToLocation.checkable)
                    }
                }

            }




        }




    }




    Component{
        id:userLoginAndReg
        Pane{
            Material.elevation: 6

            Column{
                anchors.centerIn: parent
                width:parent.width*0.6
                height:parent.height*0.6
                spacing:5
                Rectangle{
                    width: parent.width
                    height: parent.height*0.15
                    Button{
                        width: parent.width/2-10
                        height: parent.height
                        highlighted: true
                        Material.accent: Material.Blue
                        Material.roundedScale: Material.SmallScale
                        text:"登录"
                        anchors.left: parent.left

                    }
                    Button{
                        width: parent.width/2-10
                        height: parent.height
                        highlighted: true
                        Material.accent: Material.Blue
                        Material.roundedScale: Material.SmallScale
                        text:"注册"
                        enabled: false
                        anchors.right: parent.right
                    }
                }
                SwipeView{
                    id:loginAndRegSwipeView
                    width: parent.width
                    height: parent.height*0.5
                    Component.onCompleted: {
                        var login=userLogin.createObject(parent)
                        loginAndRegSwipeView.addItem(login)
                    }

                }








            }




        }


    }

    Component.onCompleted: {
        if(!isLogined){
            if(!Tool.isLogined){
                var compUserLoginAndReg= userLoginAndReg.createObject(parent)
                kuserStackView.push(compUserLoginAndReg)
                return
            }
            kuserStackView.push(compOfKUserDtailShowPage)
        }
    }
    Rectangle{
        anchors.fill: parent
        StackView{
            id:kuserStackView
            anchors.fill: parent



        }

    }
    // Component{

    KUserDtailShowPage{
        id:compOfKUserDtailShowPage
    }
    // }


    Connections{
        target: Tool
        function onLoginSuc(){
            // console.log(123);
            if(kuserStackView.depth==1){
                kuserStackView.pop()
            }
            // var COKDSP=compOfKUserDtailShowPage.createObject(parent)
            kuserStackView.push(compOfKUserDtailShowPage)

        }

    }

}
